note (Anki)のguid生成algorithm
/24.06.2/rslib/src/notes/mod.rsにnote (Anki)のUUID生成処理がある
rand::random()は指定された型内全ての範囲で乱数を生成する関数
code:rs
pub(crate) fn base91_u64() -> String {
anki_base91(rand::random())
}
fn anki_base91(n: u64) -> String {
to_base_n(
n,
b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&()*+,-./:;<=>?@[]^_`{|}~",
)
}
pub fn to_base_n(mut n: u64, table: &u8) -> String {
let mut buf = String::new();
while n > 0 {
let tablelen = table.len() as u64;
let (q, r) = (n / tablelen, n % tablelen);
buf.push(tabler as usize as char);
n = q;
}
buf.chars().rev().collect()
}
deno-ankiのguid生成関数をこれに変えた
https://github.com/takker99/deno-anki/pull/5
https://chat.openai.com/chat/13c9c79a-07bd-4e85-b328-1f085449f39b
#2024-06-17 15:58:33
#2023-02-17 11:35:31